//
//  UIButton+Extension.swift
//  GZWeibo
//
//  Created by chenbin on 15/9/22.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

extension UIButton {
    
    /**
    便利构造函数
    
    - parameter imageName:     imageName
    - parameter backImageName: 背景图像名称
    
    - returns: UIButton
    */
    convenience init(imageName: String, backImageName: String) {
        
        self.init()

        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        // 自动调整大小
        sizeToFit()
    }
    
    /**
    便利构造函数
    
    - parameter title:         title
    - parameter fontSize:      fontSize
    - parameter color:         color
    - parameter backImageName: backImageName
    
    - returns: UIbutton
    */
    convenience init(title: String, fontSize: CGFloat, color: UIColor, backImageName: String) {
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
    
}














